const posthtml = require('posthtml')
const insertScriptToBody = function (tree) {
  tree.match({ tag: 'body' }, (node) => {
    node.content.push({
      tag: 'script',
      attrs: {
        src: './js/index.js',
      },
    })
    return node
  })
}
const html = `
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
</body>
</html>
`
const insertScriptToHtml = (html) => {
  return posthtml().use(insertScriptToBody).process(html, { sync: true }).html
}
const res = insertScriptToHtml(html)
console.log(res)

